<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AIfES 2: aimath_q31.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="AIfES_logo_small.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">AIfES 2
   &#160;<span id="projectnumber">2.0.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('aimath__q31_8h_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">aimath_q31.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="aimath__q31_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;<span class="preprocessor">#ifndef AIMATH_Q31</span></div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;<span class="preprocessor">#define AIMATH_Q31</span></div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160; </div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="aifes__math_8h.html">core/aifes_math.h</a>&quot;</span></div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="aimath__basic_8h.html">basic/base/aimath/aimath_basic.h</a>&quot;</span></div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160; </div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;<span class="preprocessor">#define AITENSOR_2D_Q31(shape, params, data)    {aiq31, 2, shape, params, data}</span></div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160; </div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160; </div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;<span class="preprocessor">#define Q31_TO_FLOAT(Q, S, Z)       ((float) ((int64_t)(Q) - (int64_t)(Z)) / (float) ((int64_t) 1ULL &lt;&lt; (S)))</span></div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160; </div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;<span class="preprocessor">#define FLOAT_TO_Q31(F, S, Z)       ((int32_t) ((int64_t)((F) * (1ULL &lt;&lt; (S)) + ((F) &gt;= 0 ? 0.5f : -0.5f)) + (int64_t)(Z)))</span></div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160; </div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;<span class="preprocessor">#define AISCALAR_Q31(F, S, Z)       {FLOAT_TO_Q31(F, S, Z), S, Z}</span></div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160; </div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;<span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structaimath__q31__params.html">aimath_q31_params</a>    <a class="code" href="structaimath__q31__params.html">aimath_q31_params_t</a>;</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;<span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structaiscalar__q31.html">aiscalar_q31</a>         <a class="code" href="structaiscalar__q31.html">aiscalar_q31_t</a>;</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160; </div>
<div class="line"><a name="l00149"></a><span class="lineno"><a class="line" href="structaimath__q31__params.html">  149</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structaimath__q31__params.html">aimath_q31_params</a> {</div>
<div class="line"><a name="l00150"></a><span class="lineno"><a class="line" href="structaimath__q31__params.html#a8f20d77488fe485aaf9ea8e9c5d7d35e">  150</a></span>&#160;    uint16_t <a class="code" href="structaimath__q31__params.html#a8f20d77488fe485aaf9ea8e9c5d7d35e">shift</a>; </div>
<div class="line"><a name="l00151"></a><span class="lineno"><a class="line" href="structaimath__q31__params.html#a43cdb7ca657bf35ee727cdbae02fced9">  151</a></span>&#160;    int32_t <a class="code" href="structaimath__q31__params.html#a43cdb7ca657bf35ee727cdbae02fced9">zero_point</a>; </div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;};</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160; </div>
<div class="line"><a name="l00156"></a><span class="lineno"><a class="line" href="structaiscalar__q31.html">  156</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structaiscalar__q31.html">aiscalar_q31</a> {</div>
<div class="line"><a name="l00157"></a><span class="lineno"><a class="line" href="structaiscalar__q31.html#a01571c420f280137c16d319178731da5">  157</a></span>&#160;    int32_t <a class="code" href="structaiscalar__q31.html#a01571c420f280137c16d319178731da5">value</a>; </div>
<div class="line"><a name="l00158"></a><span class="lineno"><a class="line" href="structaiscalar__q31.html#a8f20d77488fe485aaf9ea8e9c5d7d35e">  158</a></span>&#160;    uint16_t <a class="code" href="structaiscalar__q31.html#a8f20d77488fe485aaf9ea8e9c5d7d35e">shift</a>; </div>
<div class="line"><a name="l00159"></a><span class="lineno"><a class="line" href="structaiscalar__q31.html#a43cdb7ca657bf35ee727cdbae02fced9">  159</a></span>&#160;    int32_t <a class="code" href="structaiscalar__q31.html#a43cdb7ca657bf35ee727cdbae02fced9">zero_point</a>; </div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;};</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160; </div>
<div class="line"><a name="l00172"></a><span class="lineno"><a class="line" href="aimath__q31_8h.html#a541e04ea103af9dbbd9ec41934dbf2af">  172</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="aimath__q31_8h.html#a541e04ea103af9dbbd9ec41934dbf2af">aimath_q31_print_aitensor</a>(<span class="keyword">const</span> <a class="code" href="structaitensor.html">aitensor_t</a> *tensor);</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160; </div>
<div class="line"><a name="l00184"></a><span class="lineno"><a class="line" href="aimath__q31_8h.html#a7359acc9b475f46d48ce80ef7c74114f">  184</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="aimath__q31_8h.html#a7359acc9b475f46d48ce80ef7c74114f">aimath_q31_print_aiscalar</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> *scalar);</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160; </div>
<div class="line"><a name="l00195"></a><span class="lineno"><a class="line" href="aimath__q31_8h.html#a3e5faeb8c077d061d6e8d48543b947c5">  195</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="aimath__q31_8h.html#a3e5faeb8c077d061d6e8d48543b947c5">aimath_q31_calc_q_params_from_f32</a>(<span class="keywordtype">float</span> min_value, <span class="keywordtype">float</span> max_value, <a class="code" href="structaimath__q31__params.html">aimath_q31_params_t</a> *q_params);</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160; </div>
<div class="line"><a name="l00205"></a><span class="lineno"><a class="line" href="aimath__q31_8h.html#ac204ae3be0fdc2b0ac57369254c58f1a">  205</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="aimath__q31_8h.html#ac204ae3be0fdc2b0ac57369254c58f1a">aimath_q31_quantize_tensor_from_f32</a>(<span class="keyword">const</span> <a class="code" href="structaitensor.html">aitensor_t</a> *tensor_f32, <a class="code" href="structaitensor.html">aitensor_t</a> *tensor_q31);</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160; </div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;<span class="keyword">extern</span> <span class="keyword">const</span> <a class="code" href="structaimath__dtype.html">aimath_dtype_t</a> *<a class="code" href="aimath__q31_8h.html#ac5314582da98b2cdbe4b445ea25f0b77">aiq31</a>;</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160; </div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;<span class="preprocessor">#endif </span><span class="comment">// AIMATH_Q31</span></div>
<div class="ttc" id="aaifes__math_8h_html"><div class="ttname"><a href="aifes__math_8h.html">aifes_math.h</a></div><div class="ttdoc">AIfES 2 math interface.</div></div>
<div class="ttc" id="aaimath__basic_8h_html"><div class="ttname"><a href="aimath__basic_8h.html">aimath_basic.h</a></div><div class="ttdoc">Basic data-type independent math operations.</div></div>
<div class="ttc" id="aaimath__q31_8h_html_a3e5faeb8c077d061d6e8d48543b947c5"><div class="ttname"><a href="aimath__q31_8h.html#a3e5faeb8c077d061d6e8d48543b947c5">aimath_q31_calc_q_params_from_f32</a></div><div class="ttdeci">void aimath_q31_calc_q_params_from_f32(float min_value, float max_value, aimath_q31_params_t *q_params)</div><div class="ttdoc">Calculates the aimath_q31_params parameters.</div></div>
<div class="ttc" id="aaimath__q31_8h_html_a541e04ea103af9dbbd9ec41934dbf2af"><div class="ttname"><a href="aimath__q31_8h.html#a541e04ea103af9dbbd9ec41934dbf2af">aimath_q31_print_aitensor</a></div><div class="ttdeci">void aimath_q31_print_aitensor(const aitensor_t *tensor)</div><div class="ttdoc">Printing a Q31 tensor to console.</div></div>
<div class="ttc" id="aaimath__q31_8h_html_a7359acc9b475f46d48ce80ef7c74114f"><div class="ttname"><a href="aimath__q31_8h.html#a7359acc9b475f46d48ce80ef7c74114f">aimath_q31_print_aiscalar</a></div><div class="ttdeci">void aimath_q31_print_aiscalar(const void *scalar)</div><div class="ttdoc">Printing a Q31 scalar to console.</div></div>
<div class="ttc" id="aaimath__q31_8h_html_ac204ae3be0fdc2b0ac57369254c58f1a"><div class="ttname"><a href="aimath__q31_8h.html#ac204ae3be0fdc2b0ac57369254c58f1a">aimath_q31_quantize_tensor_from_f32</a></div><div class="ttdeci">void aimath_q31_quantize_tensor_from_f32(const aitensor_t *tensor_f32, aitensor_t *tensor_q31)</div><div class="ttdoc">Converts a float f32 tensor into a quantized q31 tensor.</div></div>
<div class="ttc" id="aaimath__q31_8h_html_ac5314582da98b2cdbe4b445ea25f0b77"><div class="ttname"><a href="aimath__q31_8h.html#ac5314582da98b2cdbe4b445ea25f0b77">aiq31</a></div><div class="ttdeci">const aimath_dtype_t * aiq31</div><div class="ttdoc">The Q31 data-type indicator.</div></div>
<div class="ttc" id="astructaimath__dtype_html"><div class="ttname"><a href="structaimath__dtype.html">aimath_dtype</a></div><div class="ttdoc">Indicator for the used datatype.</div><div class="ttdef"><b>Definition:</b> aifes_math.h:44</div></div>
<div class="ttc" id="astructaimath__q31__params_html"><div class="ttname"><a href="structaimath__q31__params.html">aimath_q31_params</a></div><div class="ttdoc">Parameters used for the quantized Q31  values, used as property of a tensor.</div><div class="ttdef"><b>Definition:</b> aimath_q31.h:149</div></div>
<div class="ttc" id="astructaimath__q31__params_html_a43cdb7ca657bf35ee727cdbae02fced9"><div class="ttname"><a href="structaimath__q31__params.html#a43cdb7ca657bf35ee727cdbae02fced9">aimath_q31_params::zero_point</a></div><div class="ttdeci">int32_t zero_point</div><div class="ttdoc">The zero point  of the quantization.</div><div class="ttdef"><b>Definition:</b> aimath_q31.h:151</div></div>
<div class="ttc" id="astructaimath__q31__params_html_a8f20d77488fe485aaf9ea8e9c5d7d35e"><div class="ttname"><a href="structaimath__q31__params.html#a8f20d77488fe485aaf9ea8e9c5d7d35e">aimath_q31_params::shift</a></div><div class="ttdeci">uint16_t shift</div><div class="ttdoc">The scaling factor  of the quantization (The total scale is calculated with )</div><div class="ttdef"><b>Definition:</b> aimath_q31.h:150</div></div>
<div class="ttc" id="astructaiscalar__q31_html"><div class="ttname"><a href="structaiscalar__q31.html">aiscalar_q31</a></div><div class="ttdoc">Single quantized Q31  value/scalar.</div><div class="ttdef"><b>Definition:</b> aimath_q31.h:156</div></div>
<div class="ttc" id="astructaiscalar__q31_html_a01571c420f280137c16d319178731da5"><div class="ttname"><a href="structaiscalar__q31.html#a01571c420f280137c16d319178731da5">aiscalar_q31::value</a></div><div class="ttdeci">int32_t value</div><div class="ttdoc">Quantized value .</div><div class="ttdef"><b>Definition:</b> aimath_q31.h:157</div></div>
<div class="ttc" id="astructaiscalar__q31_html_a43cdb7ca657bf35ee727cdbae02fced9"><div class="ttname"><a href="structaiscalar__q31.html#a43cdb7ca657bf35ee727cdbae02fced9">aiscalar_q31::zero_point</a></div><div class="ttdeci">int32_t zero_point</div><div class="ttdoc">The zero point  of the quantization.</div><div class="ttdef"><b>Definition:</b> aimath_q31.h:159</div></div>
<div class="ttc" id="astructaiscalar__q31_html_a8f20d77488fe485aaf9ea8e9c5d7d35e"><div class="ttname"><a href="structaiscalar__q31.html#a8f20d77488fe485aaf9ea8e9c5d7d35e">aiscalar_q31::shift</a></div><div class="ttdeci">uint16_t shift</div><div class="ttdoc">The scaling factor  of the quantization (The total scale is calculated with )</div><div class="ttdef"><b>Definition:</b> aimath_q31.h:158</div></div>
<div class="ttc" id="astructaitensor_html"><div class="ttname"><a href="structaitensor.html">aitensor</a></div><div class="ttdoc">A tensor in AIfES.</div><div class="ttdef"><b>Definition:</b> aifes_math.h:89</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_1e5d3661ed79af157d57e64a38265d09.html">basic</a></li><li class="navelem"><a class="el" href="dir_90008ee2b0f86999412b56217da88d54.html">base</a></li><li class="navelem"><a class="el" href="dir_4fb15a30b37b64fdad6823e3082f73a4.html">aimath</a></li><li class="navelem"><a class="el" href="aimath__q31_8h.html">aimath_q31.h</a></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
